<html>
<head>
<title>Diary Testing | Email the blog!</title>
</head>

<?php 
    include ('./nav.html');
?>

<h3>Send an email!</h3>

<form name="emailform" method="post" action="email.php">
    <table border="2">
    <tr><td>Sender:</td><td><input type="text" name="sender"></td></tr>
    <tr><td>Recipient:</td><td><input type="text" name="recipient"></td></tr>
    <tr><td>Subject:</td><td><input type="text" name="subject"></td></tr>
    <tr><td valign="top">Message:</td><td><textarea name="message" cols=40 rows=6></textarea></td></tr>
    </table>
    <input type="submit" value="Send email" action="email.php">
</form>

<?php
    $from = $_POST["sender"];
    $to = $_POST["recipient"];
    $subj = $_POST["subject"];
    $msg = wordwrap($_POST["message"], 70);
    
    if($to && $from) {
        $headers = "From:".$from."\r\nReply-to:".$from."";
        echo "Email being sent...<br>";
        $mail_sent = mail($to,$subject,$msg,$headers);
        if($mail_sent) {
            echo "Mail sent!";
        } else {
            echo "Mail not sent.";
        }
    }
?>

</html>